package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.dto.SetmealDTO;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.mapper.MemberMapper;
import com.itheima.health.mapper.SetmealMapper;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Member;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.MemberService;
import com.itheima.health.service.SetmealService;
import com.itheima.health.utils.resources.RedisConstant;
import com.itheima.health.vo.CheckGroupVO;
import com.itheima.health.vo.SetmealVO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.*;

@Service(retries = 0,timeout = 10000)
@Transactional
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {


    @Override
    public Member findMemeberByTelephone(String telephone) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("PHONENUMBER",telephone);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public Map<String, List> getMemberCount(String[] dateArray) {

        String startDate = dateArray[0];
        // String substring = startDate.substring(0, 10);
        // System.out.println("startDate = " + substring);
        String endDate = dateArray[1];

        System.out.println("startDate = " + startDate);
        System.out.println("endDate = " + endDate);

        List<Map> memberCount = baseMapper.getMemberCount(startDate,endDate);

        Map<String, List> map = new HashMap<>();

        List list = new ArrayList();
        List list1 = new ArrayList();
        for (Map map1 : memberCount) {
            System.out.println("map1 = " + map1);
            list.add(map1.get("yearAndMonth"));
            list1.add(map1.get("memberCounts"));
        }
        map.put("yearAndMonth",list);
        map.put("memberCounts",list1);

        return map;
    }

    @Override
    public Map<String, List> getMemberCountAndYear() {


        List<Map>  mapList  = baseMapper.getMemberCountAndYear();

        Map<String, List> map = new HashMap<>();

        List list = new ArrayList();
        List list1 = new ArrayList();

        for (Map map1 : mapList) {
            System.out.println("map1 = " + map1);
            list.add(map1.get("yearAndMonth"));
            list1.add(map1.get("memberCounts"));
        }
        map.put("yearAndMonth",list);
        map.put("memberCounts",list1);

        return map;
    }

//    @Override
//    public Map countMemberBySexAndAge() {
//        Map mapList=baseMapper.countMemberBySexAndAge();
//    }

}



